<template>
	<view class="my-collection">
		<u-navbar :autoBack="false"
			:title="`${title}${collectionNum ? `(${collectionNum})` : `${counts ? `(${counts})` : ``}`}`"
			bgColor="#030204" safeAreaInsetTop placeholder leftIconColor="#ffffff" @leftClick="back"
			titleStyle="{fontSize: 16px;font-weight: bold;color: #FFFFFF;}">
			<view class="u-nav-slot f-base white" slot="right" style="color: white;" @click="toRecordPage">藏品记录</view>
		</u-navbar>
		<template v-if="!loading">
			<view class="p-20 full-height">
				<!-- <view class="list flex-no-horizontal" v-if="list.length">
					<view class="storages" v-if="storage">
						<view class="storageBck" @tap="onGoto()">
							<view class="cont">
								<view class="contImgs">
									<u--image src="/static/img/storageBrooch.png" width="212rpx" height="307rpx"
										mode="aspectFit" :lazy-load="true"></u--image>
								</view>
								<view class="contFont">
									艾草胸针系列藏品
								</view>
								<view class="contBtns">
									<text>查看更多</text>
									<u-icon name="arrow-right" size="22rpx" color="#F3F6FF"></u-icon>
								</view>
							</view>
						</view>
					</view>
					<collection class="list-item" v-for="(item,index) in list" v-if="!item.storageType" :key="index"
						:proData="item" @click="handle">
					</collection>
				</view> -->
				<view class="list flex-no-horizontal" v-if="collectionStorage.length || list.length">
					<view class="colltion" v-for="(item, index) in collectionStorage" :key="index"
						@click="onGoto(item)">
						<view class="cover">
							<u--image :src="item.image" width="315rpx" height="406rpx" :lazy-load="true"></u--image>
						</view>
						<view class="colltion-title border-box">
							<view style="width: 100%;">
								<view class="titles">
									{{item.display_title}}
								</view>
								<view class="numbersItem">
									<view class="count">
										x {{item.count}}
									</view>
									<view class="itemRightGoto">
										查看更多
										<u-icon name="arrow-right" color="#909193" size="11"></u-icon>
									</view>
								</view>
							</view>
						</view>
					</view>
					<!-- <view class="storages" v-if="collectionStorage">
						<view class="storageBck" @tap="onGoto()">
							<view class="cont">
								<view class="contImgs">
									<u--image src="/static/img/storageBrooch.png" width="212rpx" height="307rpx"
										mode="aspectFit" :lazy-load="true"></u--image>
								</view>
								<view class="contFont">
									艾草胸针系列藏品
								</view>
								<view class="contBtns">
									<text>查看更多</text>
									<u-icon name="arrow-right" size="22rpx" color="#F3F6FF"></u-icon>
								</view>
							</view>
						</view>
					</view> -->
					<!-- <view  class="list-item" v-for="(item,index) in list" v-if="!item.storageType" :key="index" >
						<collection @click="handle" :proData="item"></collection>
						{{item.storageType}}
					</view> -->
					<collection class="list-item" v-for="(item,index) in list"
						v-if="!item.storageType && (index + 1) > collectionStorage.length" :key="index" :proData="item"
						@click="handle">
					</collection>
				</view>
				<template v-else>
					<view class="empty" v-if="user.isAttested">
						<u--image src="../../static/img/empty-my-collection2.png" width="210" height="169"></u--image>
						<text class="f-xs m-t-20">您还没有获得藏品哦～</text>
					</view>
					<view class="empty" v-else-if="!user.idCard">
						<u--image src="../../static/img/empty-my-collection.png" width="231" height="136"></u--image>
						<text class="f-xs m-t-20">您还未实名请完成实名～</text>
						<text class="f-xxs m-t-10 m-b-30">根据国家相关法律规定，实名之后才能生成区块链地址哦～</text>
						<u-button type="success" shape="circle" color="#4ABC5A" style="width: 100px;" @click="toPage">
							去实名</u-button>
					</view>
				</template>

			</view>
		</template>
		<u-popup :show="blindBoxType" mode="center" round="20" overlayOpacity="0.8">
			<view class="warp">
				<view class="rect" @tap.stop>
					<u--image :src="openData.gif_img" width="502rpx" height="481rpx" class="cover"></u--image>
					<view class="f-xl btn text-center bold openBtnBlindBox" @click="$u.throttle(openBlind, 500)">打开盲盒
					</view>
					<view class="closeBlind">
						<u--image src="/static/img/closeBlind.png" width="52rpx" height="52rpx"
							@tap="blindBoxType = false" class="cover"></u--image>
					</view>
				</view>
			</view>
		</u-popup>
		<open-ben :show="isShowOpen" v-if="isShowOpen" :proData="openData" @onGotoPage="gotoPages" @close="closeBox">
		</open-ben>
	</view>
</template>


<script>
	import getMyCollection from '../../common/mixin/getMyCollection.js'
	import collection from './common/collection.vue'
	import openBen from './common/openBen.vue'
	export default {
		mixins: [getMyCollection],
		components: {
			collection,
			openBen
		},

		data() {
			return {
				loading: true,
				title: '我的藏品'
			}
		},
		onLoad() {
			// #ifdef APP-PLUS
			let page = this.$mp.page.$getAppWebview();
			page.setStyle({
				popGesture: 'none'
			});
			// #endif
		},
		methods: {
			onGoto(item) {
				uni.navigateTo({
					url: `/pages/collection/storageBrooch?id=${item.id}&title=${item.display_title}&count=${item.count}`
				})
			},
			back() {
				// uni.redirectTo({
				// 	url:`/pages/user/user`
				// })
				uni.switchTab({
					url: `/pages/user/user`
				})

				// uni.navigateBack()
				// uni.navigateBack({
				// 	delta: 1
				// })
			},

			toPage() {
				console.log(this.user)
				uni.navigateTo({
					url: '../user/realName'
				})
			},

			toRecordPage() {
				uni.navigateTo({
					url: './collectionRecord'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep.u-popup__content {
		background-color: transparent !important;
	}

	::v-deep .u-navbar__content__right {
		padding: 0 40rpx;
	}

	.colltion {
		border: 2rpx solid #313131;
		border-radius: 10rpx;
		overflow: hidden;
		width: 315rpx;
		box-sizing: border-box;

		.colltion-title {
			background: #1c222d;
			border-radius: 0 0 10rpx 10rpx;
			color: white;
			font-size: $uni-font-size-base;
			padding: 30rpx 20rpx;
			font-size: 24rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.titles {
				margin-bottom: 10rpx;
			}

			.numbersItem {
				display: flex;
				justify-content: space-between;

				.itemRightGoto {
					color: #909193 !important;
					display: flex;
				}
			}
		}

	}

	.colltion {
		margin: 0 40rpx 40rpx 0;

		&:nth-child(2n) {
			margin-right: 0;
		}
	}

	.storages {
		.storageBck:nth-child(2n) {
			margin-right: 0;
		}

		.storageBck {
			background: url('/static/img/storageBck.png') no-repeat;
			background-size: 100% 100%;
			margin: 0 40rpx 40rpx 0;
			width: 315rpx;
			height: 500rpx;

			.cont {
				.contImgs {
					display: flex;
					justify-content: center;
					// margin-bottom: 4rpx;
					padding: 32rpx 0 0;
				}

				.contFont {
					color: #FFFCEF;
					font-size: 28rpx;
					margin-bottom: 25rpx;
					text-align: center;
				}

				.contBtns {
					background: linear-gradient(216deg, #2F4C4D 0%, #3E735E 100%);
					padding: 19rpx 0;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 60rpx;
					width: 80%;
					margin: auto;

					text {
						color: #F3F6FF;
						font-size: 22rpx;
						margin-right: 8rpx;
						margin-left: 20rpx;
					}
				}
			}
		}
	}

	.closeBlind {
		display: flex;
		justify-content: center;
	}

	.openBtnBlindBox {
		background: linear-gradient(0deg, #FFFFFF, #E1D4FF);
		border-radius: 80rpx;
		padding: 27rpx 0;
		position: relative;
		bottom: 86rpx;
		width: 60%;
		margin: auto;
		font-size: 26rpx;
		color: #37226D;
	}

	.my-collection {
		box-sizing: border-box;
		background: #030204;
		min-height: 100%;

		.list {
			flex-wrap: wrap;
			align-items: flex-start;

			.list-item {
				margin: 0 40rpx 40rpx 0;

				&:nth-child(2n) {
					margin-right: 0;
				}
			}
		}

		.empty {
			height: calc(100vh - 120px);
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			color: #747474;
		}
	}
</style>
